//
//  ChannelNum.m
//  DianNaoWang
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "EnjoyImage.h"

@implementation EnjoyImage
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatViews];
    }
    return self;
}
-(void)creatViews
{
    _titleLabel = [[UILabel alloc]init];
    
    _titleLabel.font = contentTextSize;
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];

    
    _bigImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_bigImageView];

    
    _dataLabel = [[UILabel alloc]init];
    
    _dataLabel.font = otherTextSize;
    [self.contentView addSubview:_dataLabel];

    
    _numLabel = [[UILabel alloc]init];
    _numLabel.textColor = otherTextColor;
    _numLabel.font = otherTextSize;
    [self.contentView addSubview:_numLabel];

    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    _titleLabel.textColor = contenttextColor;
    _dataLabel.textColor = otherTextColor;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:contentTextSize, NSFontAttributeName, nil];
    CGRect rect = [_titleLabel.text boundingRectWithSize:CGSizeMake(ScreenWidth - 20 * FitWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    _titleLabel.frame = CGRectMake(10 *FitWidth, 10 *FitHeight, ScreenWidth - 20 * FitWidth, rect.size.height);
    
    NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:otherTextSize, NSFontAttributeName, nil];
    CGRect rect2 = [_numLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20 * FitHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic2 context:nil];
    
    _bigImageView.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 10 * FitHeight, ScreenWidth - 20 * FitWidth, 150 * FitHeight);
    
    _dataLabel.frame = CGRectMake(_bigImageView.frame.origin.x, _bigImageView.frame.origin.y + _bigImageView.frame.size.height + 10 * FitHeight, 100 * FitWidth, 10 * FitHeight);
    
    _numLabel.frame = CGRectMake(ScreenWidth - 10 * FitWidth - rect2.size.width, _dataLabel.frame.origin.y, rect2.size.width,  _dataLabel.frame.size.height);
}

-(void)setInfo:(TushangInfo *)info
{
    if (_info != info) {
//        _info = [info retain];
    }
    _titleLabel.text = info.title;
    [_bigImageView sd_setImageWithURL:[NSURL URLWithString:info.imgSrc] placeholderImage:[UIImage imageNamed:@"123"]];
    _dataLabel.text = [info.date substringFromIndex:5];
    _numLabel.text = [NSString stringWithFormat:@"%ld 图", info.num];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
